<?php

/**
 * Subclass for representing a row from the 'subject' table.
 *
 * 
 *
 * @package lib.model
 */ 
class Subject extends BaseSubject
{

  public function getTutors($number, $rates, $servicearea, $availability)
  {
    $c = new Criteria();
    $c->setLimit($number);
    $c->add(TutorPeer::RATES, (int)$rates, Criteria::LESS_EQUAL);
    $c->add(TutorPeer::SERVICEAREA_ID, $servicearea);

    $d = new Criteria();
    $d->add(AvailabilityTutorPeer::AVAILABILITY_ID, $availability);

    $availabilitytutors = AvailabilityTutorPeer::doSelect($d);

    $tutors = array();
     foreach($this->getSubjectTutorsJoinTutor($c) as $ref) {
	  $availabilitycheck = false;
        foreach($availabilitytutors as $availabilitytutor) {
          if ($availabilitytutor->getTutorId() == $ref->getTutor()->getId()) {
            $availabilitycheck = true;
          }
	  }
        if($availabilitycheck) {
          $tutors[] = $ref->getTutor();
        }
     }
     return $tutors;
  }

  public function __toString()
  {
    return $this->getName();
  }
}
